Skip to content

xDS unified mux: subscription states#16486

Merged
htuch merged 23 commits intoenvoyproxy:mainfrom
dmitri-d:xds-unification-part-1
Jul 9, 2021
Merged

xDS unified mux: subscription states#16486
htuch merged 23 commits intoenvoyproxy:mainfrom
dmitri-d:xds-unification-part-1

Conversation

@dmitri-d
Copy link
Contributor

Split out subscription state out of xDS mux unification PR (#15473). Made base subscription state class a template. Updated existing delta state tests to work with both legacy and new implementations.

Commit Message: xDS unified mux: subscription states
Additional Description:
Risk Level: low, the code is not being used atm
Testing: updated existing tests, added new ones
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

Ping @adisuissa. I followed your suggestion re: how to split the original PR (#15473).

@dmitri-d dmitri-d changed the title Part 1 of unified mux: subscription states xDS unified mux: subscription states May 13, 2021
@adisuissa
Copy link
Contributor

/assign @adisuissa

Dmitri Dolguikh added 2 commits May 14, 2021 10:20
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
…t.cc

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving this code.
I've left a few comments, mostly about possible refactoring that I think can be done.

envoy::service::discovery::v3::DeltaDiscoveryRequest*
DeltaSubscriptionState::getNextRequestInternal() {
auto* request = new envoy::service::discovery::v3::DeltaDiscoveryRequest;
request->set_type_url(type_url());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously, in addition to type_url, the request's node field was also updated. Why was this removed here?

Also it seems that this is something that should be generic for both Delta/SotW variants, and should be set in the parent class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is handled by mux (here: https://github.com/envoyproxy/envoy/pull/15473/files#diff-fe56236f0649ba734162e4fa294465a6004c393242c0af89421cbd5fe279fe58R341 and here: https://github.com/envoyproxy/envoy/pull/15473/files#diff-fe56236f0649ba734162e4fa294465a6004c393242c0af89421cbd5fe279fe58R398) in the new implementation, although I think you are right, conceptually it fits better with the state. I'd like to postpone this change until the PR that introduces new mux implementation, however: it's a bit tricky to keep track of changes that affect multiple classes and more importantly the logic inside. I can add a comment to that effect?

In current implementation sotw and delta muxes handle node differently (delta always sends node), the new implementation uses the approach currently used by sotw mux in both cases.

// pointer actually is.
virtual RQ* getNextRequestWithAck(const UpdateAck& ack) PURE;

void disableInitFetchTimeoutTimer() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that enabling the timer only happens during the object initialization, and then disable can be called, and there's no way to re-enable the timer. Is this intended behavior? Can you add a comment why it behaves so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only handles initial fetch timeout. Currently this is handled in the subscription (here: https://github.com/envoyproxy/envoy/blob/main/source/common/config/grpc_subscription_impl.cc#L31), but has been moved to subscription state in the new implementation. Added a comment, please let me know if it's descriptive enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for the move?

Copy link
Contributor Author

@dmitri-d dmitri-d Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was moved in the original version of this work done by Fred, and I thought it was a good call. I just noticed though that this introduced a problem under Ads: should any subscription sharing mux with other subscriptions call GrpcMux::disableInitFetchTimeoutTimer() (here: 109ac32#diff-fe56236f0649ba734162e4fa294465a6004c393242c0af89421cbd5fe279fe58R183), all subscriptions will get their init fetch timeout timers disabled. I don't think there's a way around this, I'll move the timer and corresponding calls back to subscription.

Comment on lines +53 to +55
void setDynamicContextChanged() { dynamic_context_changed_ = true; }
void clearDynamicContextChanged() { dynamic_context_changed_ = false; }
bool dynamicContextChanged() const { return dynamic_context_changed_; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be protected instead of public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protobuf::RepeatedPtrField<std::string> removed_resources;
for (const auto& resource : expired) {
resource_state_[resource] = ResourceState::waitingForServer();
removed_resources.Add(std::string(resource));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the call to the string c'tor required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a port from here: https://github.com/envoyproxy/envoy/blob/main/source/common/config/delta_subscription_state.cc#L22. My understaning is that Protobuf::RepeatedPtrField takes ownership of strings/massages added to it, hence the signature (RepeatedPtrField<T>::Add(T&& value)) and the need for a new instance of the string.

Dmitri Dolguikh added 2 commits May 17, 2021 19:07
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!
One more comment about the tests.

Comment on lines +133 to +134
std::unique_ptr<Envoy::Config::DeltaSubscriptionState> legacy_state_;
std::unique_ptr<Envoy::Config::UnifiedMux::DeltaSubscriptionState> unified_state_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be a variant?
If there's no use of both at the same time, I think it makes sense.

@adisuissa
Copy link
Contributor

/cc @htuch
I think the PR looks good.

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

  • responded to feedback

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

dmitri-d commented May 26, 2021

  • increased test coverage

@dmitri-d
Copy link
Contributor Author

Not sure why the coverage for source/common/config/unified_mux is reported so low; I have it at 96.5% locally.

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@alyssawilk
Copy link
Contributor

If you check https://github.com/envoyproxy/envoy/blob/main/source/docs/coverage.md it should show you what's missing
there are some quirks to coverage you may be hitting?

@alyssawilk
Copy link
Contributor

Yan: can you cover code reviews until @htuch gets back?

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

dmitri-d commented Jun 2, 2021

@adisuissa: discovered an issue with how I was handling ttl resources in SotW; fixed now. Also expanded test coverage.

Dmitri Dolguikh added 7 commits June 3, 2021 11:02
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
yanavlasov
yanavlasov previously approved these changes Jun 9, 2021
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

ping @yanavlasov

@dmitri-d
Copy link
Contributor Author

@htuch: any chance you could take a look?

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmitri-d, this looks great! Thanks for breaking out the mega PR. This mostly looks good to me, but a few comments here and there to get started.
/wait

class SubscriptionState : public Logger::Loggable<Logger::Id::config> {
public:
// Note that, outside of tests, we expect callbacks to always be a WatchMap.
SubscriptionState(std::string type_url, UntypedConfigUpdateCallbacks& callbacks,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: const std::string& or absl::string_view

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see the comment below.

// pointer actually is.
virtual RQ* getNextRequestWithAck(const UpdateAck& ack) PURE;

void disableInitFetchTimeoutTimer() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for the move?

: public SubscriptionState<envoy::service::discovery::v3::DeltaDiscoveryResponse,
envoy::service::discovery::v3::DeltaDiscoveryRequest> {
public:
DeltaSubscriptionState(std::string type_url, UntypedConfigUpdateCallbacks& watch_map,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you check all the places you are passing strings as args and move them to refs/string_views?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked string parameters in ctors. In ctor implementations, the initial copy is being moved all the way to the base class member initialization (here: https://github.com/envoyproxy/envoy/pull/16486/files#diff-807032428ceb00bb04de1be63707b2ae3dccaa00912341208fd4b8da55993b17R38).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is OK, but it's a bit counter-intuitive to someone reading the interface. Usually prefer to pass by reference and then leave the copy internally.

Dmitri Dolguikh added 2 commits July 5, 2021 15:03
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
@dmitri-d
Copy link
Contributor Author

dmitri-d commented Jul 6, 2021

  • merged changes from main
  • responded to feedback

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@htuch htuch merged commit eb3658a into envoyproxy:main Jul 9, 2021
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
Split out subscription state out of xDS mux unification PR (envoyproxy#15473). Made base subscription state class a template. Updated existing delta state tests to work with both legacy and new implementations.

Risk Level: low, the code is not being used atm
Testing: updated existing tests, added new ones

Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants